package douyin

import (
	"encoding/json"
	"github.com/zeromicro/go-zero/core/logx"
	"io"
	"xialou_platform/app/tools"
)

type NotifyReq struct {
	AccessToken string                 `json:"access_token"`
	AppId       string                 `json:"app_id"`
	TplId       string                 `json:"tpl_id"`
	OpenId      string                 `json:"open_id"`
	Data        map[string]interface{} `json:"data"`
	Page        string                 `json:"page"`
}
type NotifyResp struct {
	ErrNo   int    `json:"err_no"`
	ErrTips string `json:"err_tips"`
}

func (c *DouYinClient) SendNotify(req *NotifyReq) (*NotifyResp, error) {
	resp, err := tools.Post(NotifyUrl, req)
	if err != nil {
		logx.Errorf("err:%+v", err)
		return nil, err
	}
	var data NotifyResp
	all, err := io.ReadAll(resp.Body)
	err = json.Unmarshal(all, &data)
	if err != nil {
		logx.Errorf("err:%+v", err)
		return nil, err
	}
	return &data, nil
}
